﻿/*
Copyright (c) 2010, hiSoft
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
    * Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer in the
      documentation and/or other materials provided with the distribution.
    * Neither the name of the hiSoft nor the
      names of its contributors may be used to endorse or promote products
      derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE HISOFT AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL HISOFT BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Orchard.Test.Library;
using Selenium;

namespace Orchard.Test.Modules.Widgets.Auto
{
    [TestClass]
    public class AddLayerUnderIronRubyScriptingDLR
    {
        private TestLibrary TestLibrary;
        private ISelenium selenium;

        [TestInitialize]
        public void SetupTest()
        {
            TestLibrary = TestLibrary.SetupTest(this.ToString());
            selenium = TestLibrary.Selenium;
        }

        [TestCleanup]
        public void TeardownTest()
        {
            TestLibrary.ShutDown();
        }

        private string addLayerMsg = "Your Layer has been created";
        private string addWidgetMsg = "Your Html Widget has been added";

        [TestMethod]
        public void Widget_AddLayerUnderIronRubyScriptingDLR()  //Test for scripting DLR
        {
            string errorMessage = "";
            string user = TestLibrary.Consts.AdminUserName;
            string widgetpartlocator = "Widgets/EditWidget/";            
           
            try
            {
                TestLibrary.UserHelper.LogOnAsAdmin();
                TestLibrary.ModuleHelper.EnableScriptingDLR();
                Assert.IsTrue(selenium.IsTextPresent("DLR Scripting was enabled"), "Bug? please check if feature 'ScriptingDLR' was enabled sucessfully");
                TestLibrary.ModuleHelper.DisableLightWeightScripting();
                Assert.IsTrue(selenium.IsTextPresent("Lightweight scripting was disabled"), "Bug? please check if feature 'LightWeightScripting' was disabled sucessfully");
                #region add some layers
                
                var layer00 = TestLibrary.WidgetHelper.AddWidgetLayer("layer000", user, "this is layer00", "url('')");
                Assert.IsTrue(selenium.IsTextPresent(addLayerMsg));
                var layer = TestLibrary.WidgetHelper.AddWidgetLayer("layer001", user, "this is layer01", "url ('~/default*') and !authenticated");
                Assert.IsTrue(selenium.IsTextPresent(addLayerMsg));
                var layer02 = TestLibrary.WidgetHelper.AddWidgetLayer("layer002", user, "this is layer02", "url ('~/home*') || authenticated");
                Assert.IsTrue(selenium.IsTextPresent(addLayerMsg));
                var layer002 = TestLibrary.WidgetHelper.AddWidgetLayer("layer0002", user, "this is layer02", "url ('~/home*') or authenticated");
                Assert.IsTrue(selenium.IsTextPresent(addLayerMsg));
                var layer03 = TestLibrary.WidgetHelper.AddWidgetLayer("layer003", user, "this is layer03", "url ('~/default*') && authenticated");
                Assert.IsTrue(selenium.IsTextPresent(addLayerMsg));
                var layer003 = TestLibrary.WidgetHelper.AddWidgetLayer("layer0003", user, "this is layer003", "url ('~/default*') and authenticated");
                Assert.IsTrue(selenium.IsTextPresent(addLayerMsg));

                var layer04 = TestLibrary.WidgetHelper.AddWidgetLayer("layer004", user, "this is layer04", " url ('~/default*') || url('~/home*') and 123==123");
                Assert.IsTrue(selenium.IsTextPresent(addLayerMsg));
                var layer05 = TestLibrary.WidgetHelper.AddWidgetLayer("layer005", user, "this is layer05", " url ('~/default*' and '~/home*') && 123>122");
                Assert.IsTrue(selenium.IsTextPresent(addLayerMsg));

                var layer09 = TestLibrary.WidgetHelper.AddWidgetLayer("layer009", user, "this is layer09", " url ('~/default*') and 2==1*2");
                Assert.IsTrue(selenium.IsTextPresent(addLayerMsg));
                var layer10 = TestLibrary.WidgetHelper.AddWidgetLayer("layer010", user, "this is layer10", " url ('~/default*') and 2==2*2");
                Assert.IsTrue(selenium.IsTextPresent(addLayerMsg));
                var layer11 = TestLibrary.WidgetHelper.AddWidgetLayer("layer011", user, "this is layer11", " url ('~/default*') and 2==4/2");
                Assert.IsTrue(selenium.IsTextPresent(addLayerMsg));
                var layer12 = TestLibrary.WidgetHelper.AddWidgetLayer("layer012", user, "this is layer12", " url ('~/default*') and 2==4/4");
                Assert.IsTrue(selenium.IsTextPresent(addLayerMsg));
                var layer17 = TestLibrary.WidgetHelper.AddWidgetLayer("layer017", user, "this is layer17", " url ('~/default*') and 'a'=='a'");  //true
                Assert.IsTrue(selenium.IsTextPresent(addLayerMsg));
                var layer18 = TestLibrary.WidgetHelper.AddWidgetLayer("layer018", user, "this is layer18", " url ('~/default*') and '\\\\'=='\\\\'"); //true
                Assert.IsTrue(selenium.IsTextPresent(addLayerMsg));
                var layer19 = TestLibrary.WidgetHelper.AddWidgetLayer("layer019", user, "this is layer19", " url ('~/default*') and '_'=='_'"); //true
                Assert.IsTrue(selenium.IsTextPresent(addLayerMsg));
                var layer20 = TestLibrary.WidgetHelper.AddWidgetLayer("layer020", user, "this is layer20", " url ('~/default*') and '_+s'=='_+s'"); //true
                Assert.IsTrue(selenium.IsTextPresent(addLayerMsg));
                var layer21 = TestLibrary.WidgetHelper.AddWidgetLayer("layer021", user, "this is layer21", " url ('~/default*') and '16'==16");  //false

                //the following rule is invalid under LightWeightScripting,but consider as valid under IronRubyScriptingDLR, they are different.
                var layer22 = TestLibrary.WidgetHelper.AddWidgetLayer("Layer022", TestLibrary.Consts.AdminUserName, "This is layer22", "url ('~/default*') and 'a'>'b'");
                Assert.IsTrue(selenium.IsTextPresent(addLayerMsg));

                var layer24 = TestLibrary.WidgetHelper.AddWidgetLayer("Layer024", TestLibrary.Consts.AdminUserName, "This is layer24", "url ('~/default*') and '16'+'15'=='1615'");
                Assert.IsTrue(selenium.IsTextPresent(addLayerMsg));
                var layer25 = TestLibrary.WidgetHelper.AddWidgetLayer("Layer025", TestLibrary.Consts.AdminUserName, "This is layer25", "url ('~/default*') and 10==8.0+2.0");
                Assert.IsTrue(selenium.IsTextPresent(addLayerMsg));
                var layer26 = TestLibrary.WidgetHelper.AddWidgetLayer("Layer026", TestLibrary.Consts.AdminUserName, "This is layer26", "url ('~/default*') and 10<12345678912");
                Assert.IsTrue(selenium.IsTextPresent(addLayerMsg));
                var layer27 = TestLibrary.WidgetHelper.AddWidgetLayer("Layer027", TestLibrary.Consts.AdminUserName, "This is layer27", "url ('~/default*') and (10>1)==123");
                Assert.IsTrue(selenium.IsTextPresent(addLayerMsg));
                var layer28 = TestLibrary.WidgetHelper.AddWidgetLayer("Layer028", TestLibrary.Consts.AdminUserName, "This is layer28", "url ('~/default*') and 3==false");
                Assert.IsTrue(selenium.IsTextPresent(addLayerMsg));
                var layer29 = TestLibrary.WidgetHelper.AddWidgetLayer("Layer029", TestLibrary.Consts.AdminUserName, "This is layer29", "url ('~/default*') and !null");
                Assert.IsTrue(selenium.IsTextPresent(addLayerMsg));
                var layer30 = TestLibrary.WidgetHelper.AddWidgetLayer("Layer030", TestLibrary.Consts.AdminUserName, "This is layer30", "url ('~/default*') and  ! nil");
                Assert.IsTrue(selenium.IsTextPresent(addLayerMsg));
                var layer31 = TestLibrary.WidgetHelper.AddWidgetLayer("Layer031", TestLibrary.Consts.AdminUserName, "This is layer31", "url ('~/default*') and  1 || 2");
               
                //using "matching" operator(=~) in rule expression
                var layer32 = TestLibrary.WidgetHelper.AddWidgetLayer("Layer032", TestLibrary.Consts.AdminUserName, "This is layer32", ("url('~/default*') and ('bad' =~ /a/)<2"));  //true  the value of 'bad' =~ /a/ is 1
                Assert.IsTrue(selenium.IsTextPresent(addLayerMsg));
                //using "Set&Get Value" function in rule expression
                var layer33 = TestLibrary.WidgetHelper.AddWidgetLayer("Layer033", TestLibrary.Consts.AdminUserName, "This is layer33", ("url('~/default*') && (i=1+1)==(j=2-0) && i==j"));  //true  
                Assert.IsTrue(selenium.IsTextPresent(addLayerMsg));
                var layer3302 = TestLibrary.WidgetHelper.AddWidgetLayer("Layer03302", TestLibrary.Consts.AdminUserName, "This is layer3302", ("f=4 \r\n f==4 and url('~/default*')"));  //true  
                Assert.IsTrue(selenium.IsTextPresent(addLayerMsg));
                //use 'def' reserved keywords
                var layer34=TestLibrary.WidgetHelper.AddWidgetLayer("Layer034", TestLibrary.Consts.AdminUserName, "This is layer34", " def f\r\nreturn 32\r\nend\r\n f/4==8");
                Assert.IsTrue(selenium.IsTextPresent(addLayerMsg));
                var layer3402 = TestLibrary.WidgetHelper.AddWidgetLayer("Layer03402", TestLibrary.Consts.AdminUserName, "This is layer3402", " def f\r\n f=4\r\n end\r\n f/4==1 and url('~/default*')");
                Assert.IsTrue(selenium.IsTextPresent(addLayerMsg));
                //use 'eval' reserved keywords
                var layer35=TestLibrary.WidgetHelper.AddWidgetLayer("Layer035", TestLibrary.Consts.AdminUserName, "This is layer35", " (eval ('1'+'1'))==11");
                Assert.IsTrue(selenium.IsTextPresent(addLayerMsg));
                //use ' ? :' condition statement
                var layer36=TestLibrary.WidgetHelper.AddWidgetLayer("Layer036", TestLibrary.Consts.AdminUserName, "This is layer36", " 1+1==2?  url('~/default*'): url('~/home*')");
                Assert.IsTrue(selenium.IsTextPresent(addLayerMsg));
                //use 'if else end' condition statement
                var layer37=TestLibrary.WidgetHelper.AddWidgetLayer("Layer037", TestLibrary.Consts.AdminUserName, "This is layer37", " begin \r\n if(1+1==2)\r\n url('~/default*') \r\n else url('~/homepage*') \r\n end \r\nend");
                Assert.IsTrue(selenium.IsTextPresent(addLayerMsg));
                
                //execute ruby "testIronRuby.rb" file
                //string rubyFilePath=TestLibrary.Consts.OrchardTestDataPath+"\\testIronRuby.rb";
                var layer38 = TestLibrary.WidgetHelper.AddWidgetLayer("Layer038", TestLibrary.Consts.AdminUserName, "This is layer38", "IronRuby.CreateEngine().ExecuteFile(\"D:\\\\Workspace\\\\orchard.test\\\\Orchard.Test\\\\TestData\\\\testIronRuby.rb\") and url('~/homepage*')");
                Assert.IsTrue(selenium.IsTextPresent(addLayerMsg)); 

                #endregion
               
                var homepage1 = TestLibrary.PageHelper.CreatePage(new PageSettings { Title = "homepage1", Permalink = "homepage1", PublishSetting = PublishSettings.PublishNow });
            
                #region add widget for above added layers
                //widget01 will display on default* page and when not login
                
                var widget00 = TestLibrary.WidgetHelper.AddHtmlWidget(layer, WidgetZone.Header, "widget4layer00", 1, user, "widget00 for layer which rule with logicalidentifier");
                Assert.IsTrue(selenium.IsTextPresent(addWidgetMsg));
                var widget01 = TestLibrary.WidgetHelper.AddHtmlWidget(layer, WidgetZone.Header, "widget4layer01", 1, user, "widget01 for layer which rule with logicalidentifier");
                Assert.IsTrue(selenium.IsTextPresent(addWidgetMsg));
                var widget02 = TestLibrary.WidgetHelper.AddHtmlWidget(layer02, WidgetZone.Header, "widget4layer02", 1, user, "widget for layer which rule with logicalidentifier");
                Assert.IsTrue(selenium.IsTextPresent(addWidgetMsg));
                var widget002 = TestLibrary.WidgetHelper.AddHtmlWidget(layer002, WidgetZone.Header, "widget4layer002", 1, user, "widget for layer which rule with logicalidentifier");
                Assert.IsTrue(selenium.IsTextPresent(addWidgetMsg));
                var widget03 = TestLibrary.WidgetHelper.AddHtmlWidget(layer03, WidgetZone.Header, "widget4layer03", 1, user, "widget for layer which rule with logicalidentifier");
                Assert.IsTrue(selenium.IsTextPresent(addWidgetMsg));
                var widget003 = TestLibrary.WidgetHelper.AddHtmlWidget(layer003, WidgetZone.Header, "widget4layer003", 1, user, "widget for layer which rule with logicalidentifier");
                Assert.IsTrue(selenium.IsTextPresent(addWidgetMsg));
                var widget04 = TestLibrary.WidgetHelper.AddHtmlWidget(layer04, WidgetZone.Header, "widget4layer04", 1, user, "widget for layer which rule with logicalidentifier");
                Assert.IsTrue(selenium.IsTextPresent(addWidgetMsg));
                var widget05 = TestLibrary.WidgetHelper.AddHtmlWidget(layer05, WidgetZone.Header, "widget4layer05", 1, user, "widget for layer which rule with logicalidentifier");
                Assert.IsTrue(selenium.IsTextPresent(addWidgetMsg));

                var widget09 = TestLibrary.WidgetHelper.AddHtmlWidget(layer09, WidgetZone.Header, "widget4layer09", 1, user, "widget for layer which rule with logicalidentifier");
                Assert.IsTrue(selenium.IsTextPresent(addWidgetMsg));
                var widget10 = TestLibrary.WidgetHelper.AddHtmlWidget(layer10, WidgetZone.Header, "widget4layer10", 1, user, "widget for layer which rule with logicalidentifier");
                Assert.IsTrue(selenium.IsTextPresent(addWidgetMsg));
                var widget11 = TestLibrary.WidgetHelper.AddHtmlWidget(layer11, WidgetZone.Header, "widget4layer11", 1, user, "widget for layer which rule with logicalidentifier");
                Assert.IsTrue(selenium.IsTextPresent(addWidgetMsg));
                var widget12 = TestLibrary.WidgetHelper.AddHtmlWidget(layer12, WidgetZone.Header, "widget4layer12", 1, user, "widget for layer which rule with logicalidentifier");
                Assert.IsTrue(selenium.IsTextPresent(addWidgetMsg));

                var widget17 = TestLibrary.WidgetHelper.AddHtmlWidget(layer17, WidgetZone.Header, "widget4layer17", 1, user, "widget for layer which rule with logicalidentifier");
                Assert.IsTrue(selenium.IsTextPresent(addWidgetMsg));
                var widget18 = TestLibrary.WidgetHelper.AddHtmlWidget(layer18, WidgetZone.Header, "widget4layer18", 1, user, "widget for layer which rule with logicalidentifier");
                Assert.IsTrue(selenium.IsTextPresent(addWidgetMsg));
                var widget19 = TestLibrary.WidgetHelper.AddHtmlWidget(layer19, WidgetZone.Header, "widget4layer19", 1, user, "widget for layer which rule with logicalidentifier");
                Assert.IsTrue(selenium.IsTextPresent(addWidgetMsg));
                var widget20 = TestLibrary.WidgetHelper.AddHtmlWidget(layer20, WidgetZone.Header, "widget4layer20", 1, user, "widget for layer which rule with logicalidentifier");
                Assert.IsTrue(selenium.IsTextPresent(addWidgetMsg));
                var widget21 = TestLibrary.WidgetHelper.AddHtmlWidget(layer21, WidgetZone.Header, "widget4layer21", 1, user, "widget for layer which rule with logicalidentifier");
                Assert.IsTrue(selenium.IsTextPresent(addWidgetMsg));

                var widget22 = TestLibrary.WidgetHelper.AddHtmlWidget(layer22, WidgetZone.Header, "widget4layer22", 1, user, "widget for layer which rule with logicalidentifier");
                Assert.IsTrue(selenium.IsTextPresent(addWidgetMsg));

                var widget24 = TestLibrary.WidgetHelper.AddHtmlWidget(layer24, WidgetZone.Header, "widget4layer24", 1, user, "widget for layer which rule with logicalidentifier");
                Assert.IsTrue(selenium.IsTextPresent(addWidgetMsg));
                var widget25 = TestLibrary.WidgetHelper.AddHtmlWidget(layer25, WidgetZone.Header, "widget4layer25", 1, user, "widget for layer which rule with logicalidentifier");
                Assert.IsTrue(selenium.IsTextPresent(addWidgetMsg));
                var widget26 = TestLibrary.WidgetHelper.AddHtmlWidget(layer26, WidgetZone.Header, "widget4layer26", 1, user, "widget for layer which rule with logicalidentifier");
                Assert.IsTrue(selenium.IsTextPresent(addWidgetMsg));

                var widget27 = TestLibrary.WidgetHelper.AddHtmlWidget(layer27, WidgetZone.Header, "widget4layer27", 1, user, "widget for layer which rule with logicalidentifier");
                Assert.IsTrue(selenium.IsTextPresent(addWidgetMsg));
                var widget28 = TestLibrary.WidgetHelper.AddHtmlWidget(layer28, WidgetZone.Header, "widget4layer28", 1, user, "widget for layer which rule with logicalidentifier");
                Assert.IsTrue(selenium.IsTextPresent(addWidgetMsg));
                var widget29 = TestLibrary.WidgetHelper.AddHtmlWidget(layer29, WidgetZone.Header, "widget4layer29", 1, user, "widget for layer which rule with logicalidentifier");
                Assert.IsTrue(selenium.IsTextPresent(addWidgetMsg));
                var widget30 = TestLibrary.WidgetHelper.AddHtmlWidget(layer30, WidgetZone.Header, "widget4layer30", 1, user, "widget for layer which rule with logicalidentifier");
                Assert.IsTrue(selenium.IsTextPresent(addWidgetMsg));
                var widget31 = TestLibrary.WidgetHelper.AddHtmlWidget(layer31, WidgetZone.Header, "widget4layer31", 1, user, "widget for layer which rule with logicalidentifier");
                Assert.IsTrue(selenium.IsTextPresent(addWidgetMsg));
                var widget32 = TestLibrary.WidgetHelper.AddHtmlWidget(layer32, WidgetZone.Header, "widget4layer32", 1, user, "widget for layer which rule with logicalidentifier");
                Assert.IsTrue(selenium.IsTextPresent(addWidgetMsg));

                var widget33 = TestLibrary.WidgetHelper.AddHtmlWidget(layer33, WidgetZone.Header, "widget4layer33", 1, user, "widget for layer which rule with logicalidentifier");
                Assert.IsTrue(selenium.IsTextPresent(addWidgetMsg));
                var widget34 = TestLibrary.WidgetHelper.AddHtmlWidget(layer34, WidgetZone.Header, "widget4layer34", 1, user, "widget for layer which rule with logicalidentifier");
                Assert.IsTrue(selenium.IsTextPresent(addWidgetMsg));
                var widget35 = TestLibrary.WidgetHelper.AddHtmlWidget(layer35, WidgetZone.Header, "widget4layer35", 1, user, "widget for layer which rule with logicalidentifier");
                Assert.IsTrue(selenium.IsTextPresent(addWidgetMsg));
                var widget36 = TestLibrary.WidgetHelper.AddHtmlWidget(layer36, WidgetZone.Header, "widget4layer36", 1, user, "widget for layer which rule with logicalidentifier");
                Assert.IsTrue(selenium.IsTextPresent(addWidgetMsg));
                var widget37 = TestLibrary.WidgetHelper.AddHtmlWidget(layer37, WidgetZone.Header, "widget4layer37", 1, user, "widget for layer which rule with logicalidentifier");
                Assert.IsTrue(selenium.IsTextPresent(addWidgetMsg));
               
                var widget38 = TestLibrary.WidgetHelper.AddHtmlWidget(layer38, WidgetZone.Header, "widget4layer38", 1, user, "widget for layer which rule with logicalidentifier");
                Assert.IsTrue(selenium.IsTextPresent(addWidgetMsg));

                #endregion
               
                #region assert if specail widget display correctly on special page
                //Note: Under IronRubyScriptingDLR, "&&" not equal to "and", "||" not equal to "Or"
                selenium.Open("/default-test-page");
                Assert.IsFalse(selenium.GetHtmlSource().Contains(widgetpartlocator + widget00.Id));
                Assert.IsFalse(selenium.GetHtmlSource().Contains(widgetpartlocator + widget01.Id));
                Assert.IsFalse(selenium.GetHtmlSource().Contains(widgetpartlocator + widget02.Id));
                Assert.IsTrue(selenium.IsTextPresent(widget002.Title));
                Assert.IsFalse(selenium.GetHtmlSource().Contains(widgetpartlocator + widget03.Id));
                Assert.IsTrue(selenium.IsTextPresent(widget003.Title));
                Assert.IsTrue(selenium.IsTextPresent(widget04.Title));
                Assert.IsFalse(selenium.GetHtmlSource().Contains(widgetpartlocator + widget05.Id));

                Assert.IsTrue(selenium.IsTextPresent(widget09.Title));
                Assert.IsFalse(selenium.GetHtmlSource().Contains(widgetpartlocator + widget10.Id));
                Assert.IsTrue(selenium.IsTextPresent(widget11.Title));
                Assert.IsFalse(selenium.GetHtmlSource().Contains(widgetpartlocator + widget12.Id));

                Assert.IsTrue(selenium.IsTextPresent(widget17.Title));
                Assert.IsTrue(selenium.IsTextPresent(widget18.Title));
                Assert.IsTrue(selenium.IsTextPresent(widget19.Title));
                Assert.IsTrue(selenium.IsTextPresent(widget20.Title));

                Assert.IsTrue(selenium.IsTextPresent(widget24.Title));
                Assert.IsTrue(selenium.IsTextPresent(widget25.Title));
                Assert.IsTrue(selenium.IsTextPresent(widget26.Title));

                Assert.IsTrue(selenium.IsTextPresent(widget29.Title));
                Assert.IsTrue(selenium.IsTextPresent(widget30.Title));
                Assert.IsTrue(selenium.IsTextPresent(widget32.Title));

                Assert.IsTrue(selenium.IsTextPresent(widget33.Title));
                Assert.IsTrue(selenium.IsTextPresent(widget34.Title));
                Assert.IsTrue(selenium.IsTextPresent(widget35.Title));
                Assert.IsTrue(selenium.IsTextPresent(widget36.Title));
                Assert.IsTrue(selenium.IsTextPresent(widget37.Title));

                selenium.Open("/homepage1");
                Assert.IsTrue(selenium.IsTextPresent(widget02.Title));
                Assert.IsTrue(selenium.IsTextPresent(widget002.Title));
                Assert.IsTrue(selenium.IsTextPresent(widget34.Title));
                Assert.IsTrue(selenium.IsTextPresent(widget35.Title));
                Assert.IsTrue(selenium.IsTextPresent(widget38.Title));
               
                selenium.Open("/");
                Assert.IsTrue(selenium.IsTextPresent(widget002.Title));
                Assert.IsTrue(selenium.IsTextPresent(widget34.Title));
                Assert.IsTrue(selenium.IsTextPresent(widget35.Title));
                #endregion

                TestLibrary.UserHelper.LogOff();
                selenium.Open("/homepage1");
                #region assert if widgets display correctly
                Assert.IsTrue(selenium.IsTextPresent(widget02.Title));
                Assert.IsTrue(selenium.IsTextPresent(widget002.Title));
                Assert.IsTrue(selenium.IsTextPresent(widget34.Title));
                Assert.IsTrue(selenium.IsTextPresent(widget35.Title));            
             
                selenium.Open("/default-test-page");
                Assert.IsTrue(selenium.IsTextPresent(widget00.Title));
                Assert.IsTrue(selenium.IsTextPresent(widget01.Title));
                Assert.IsFalse(selenium.GetHtmlSource().Contains(widgetpartlocator + widget02.Id));
                Assert.IsFalse(selenium.GetHtmlSource().Contains(widgetpartlocator + widget002.Id));
                Assert.IsFalse(selenium.GetHtmlSource().Contains(widgetpartlocator + widget03.Id));
                Assert.IsFalse(selenium.GetHtmlSource().Contains(widgetpartlocator + widget003.Id));
                Assert.IsTrue(selenium.IsTextPresent(widget04.Title));
                Assert.IsTrue(selenium.IsTextPresent(widget09.Title));
                Assert.IsTrue(selenium.IsTextPresent(widget11.Title));
                Assert.IsTrue(selenium.IsTextPresent(widget17.Title));
                Assert.IsTrue(selenium.IsTextPresent(widget18.Title));
                Assert.IsTrue(selenium.IsTextPresent(widget20.Title));
                Assert.IsTrue(selenium.IsTextPresent(widget24.Title));
                Assert.IsTrue(selenium.IsTextPresent(widget25.Title));
                Assert.IsTrue(selenium.IsTextPresent(widget26.Title));
                Assert.IsTrue(selenium.IsTextPresent(widget29.Title));
                Assert.IsTrue(selenium.IsTextPresent(widget30.Title));
                Assert.IsTrue(selenium.IsTextPresent(widget32.Title));
                Assert.IsTrue(selenium.IsTextPresent(widget33.Title));
                Assert.IsTrue(selenium.IsTextPresent(widget34.Title));
                Assert.IsTrue(selenium.IsTextPresent(widget35.Title));
                Assert.IsTrue(selenium.IsTextPresent(widget36.Title));
                Assert.IsTrue(selenium.IsTextPresent(widget37.Title));
                Assert.IsFalse(selenium.IsTextPresent(widget03.Title));

                selenium.Open("/");
                Assert.IsFalse(selenium.GetHtmlSource().Contains(widgetpartlocator + widget002.Id));
                Assert.IsTrue(selenium.IsTextPresent(widget34.Title));
                Assert.IsTrue(selenium.IsTextPresent(widget35.Title));
                #endregion
                 
            }
            catch (Exception ex)
            {
                errorMessage += ex.ToString();
            }
            finally
            {
                if (errorMessage.Length > 1)
                    Assert.IsTrue(false, errorMessage);
            }
        }
    }
}
